package LuoGu.搜索.全排列;

import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    static int [] check = new int [10];
    static int [] ans = new int [10];
    static PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out));
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int first = 0;
        out_ans(first,n);
        out.flush();
    }

    public static void out_ans(int first, int n){
        if(first==n){
            for(int i=1;i<=n;i++){
                out.print(String.format("%5d",ans[i]));
            }
            out.println();
        }
        for(int i=1;i<=n;i++){
            if(check[i]==0){
                check[i] = 1;
                ans[first+1] = i;
                out_ans(first+1,n);
                check[i] = 0;
            }
        }
    }
}
